home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -websites- / wirenet / files / thor26_arexx.lha / Rexx / HeaderManager.thor < prev    next >
Text File  |  1999-01-17  |  12KB  |  391 lines

  1. /*
  2. $VER: HeaderManager.thor 1.16 (30.12.98)
  3. (c)  Neil Bothwick <neil@wirenet.co.uk>
  4. */
  5.  
  6. /* Adds, edits and deletes header lines in Thor events  */
  7.  
  8. /* Thanks to ForwardMsg.thor by Petter Nilsen for some  */
  9. /* of the user database code                            */
  10.  
  11. options results
  12.  
  13. /* ;;; needs THOR and bbsread.library functions */
  14. thorport = address()
  15. if left(thorport,5) ~= 'THOR.' then do
  16.     say 'Headers.thor must be run from within Thor.'
  17.     end
  18.  
  19. if ~show('p', 'BBSREAD') then do
  20.     address command
  21.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  22.     'WaitForPort BBSREAD'
  23.     end
  24. ;;;
  25. /* ;;; Initialise and create menus */
  26. Changed = 0
  27. drop Menu. HdrMenu.
  28. Menu.1 = '""'
  29. Menu.2 = '"Add new header"'
  30. Menu.3 = '""'
  31. Menu.4 = '"Save and exit"'
  32. Menu.5 = '""'
  33. Menu.6 = '"HELP"'
  34. Menu.Count = 6
  35. HdrMenu.1 = 'Cc:'
  36. HdrMenu.2 = 'Bcc:'
  37. HdrMenu.3 = 'Followup-To:'
  38. HdrMenu.4 = 'Reply-To:'
  39. HdrMenu.5 = 'Custom'
  40. HdrMenu.Count = 5
  41. ThorPath = pragma('D')
  42. MaxHeaderLength = 155
  43. ;;;
  44. /* ;;; Read system details */
  45. address(thorport)
  46. drop GLOBALCFG. CURRENT. BBS.
  47. GETGLOBALCONFIG stem GLOBALCFG
  48. CURRENTSYSTEM stem CURRENT
  49. System = CURRENT.BBSNAME
  50. address(bbsread)
  51. GETBBSDATA bbsname '"'System'"' stem BBS
  52. MailAddr = BBS.EMAILADDR
  53. DataPath = BBS.BBSPATH
  54. ;;;
  55. /* ;;;Get number of selected event */
  56. address(thorport)
  57. GETSELECTEDEVENT
  58. if RC > 0 then do
  59.     address(thorport)
  60.     errstring = THOR.LASTERROR
  61.     if RC = 5 then errstring = 'Event window not open'
  62.     call ExitMsg(errstring)
  63.     end
  64. EventNo = result
  65. ;;;
  66. /* ;;;Get event details */
  67. address(bbsread)
  68. READBREVENT '"'System'"' eventnr EventNo datastem EVENTDATA tagsstem EVENTTAGS
  69. if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
  70. if (EVENTDATA.EVENTTYPE > 1) & (EVENTDATA.EVENTTYPE ~= 9) then call ExitMsg('You can only edit the headers\nfor an Enter, Reply or Forward event')
  71. MsgFile = DataPath||EVENTTAGS.MSGFILE
  72. if pos('.',EVENTTAGS.CONFERENCE) > 0 then IsNews = 1
  73. else IsNews = 0
  74. ;;;
  75. /* ;;;Main loop */
  76. call ReadHeaders
  77. do until StopEdit = 1
  78.     StopEdit = MainMenu()
  79.     end
  80.  
  81. address(thorport)
  82. if Changed = 1 then REQUESTNOTIFY '"You have changed some headers.\nDo you want to save them before exiting?"' '"_Yes|_No"'
  83. if RC = 30 then call ExitMsg(THOR.LASTERROR)
  84. if result = 1 then call WriteHeaders
  85. exit
  86. ;;;
  87. /* ;;;Show messages to user */
  88. ShowMsg:
  89.     OldAddr = address()
  90.     address(thorport)
  91.     parse arg MsgStr
  92.     REQUESTNOTIFY '"'MsgStr'"' '" OK "'
  93.     address(OldAddr)
  94.     return
  95. ;;;
  96. /* ;;;Exit with a message */
  97. ExitMsg:
  98.     parse arg errmsg
  99.     call ShowMsg(errmsg)
  100.     exit
  101. ;;;
  102. /* ;;;Show main menu */
  103. MainMenu:
  104.     address(thorport)
  105.     do i = 1 to Menu.Count
  106.         interpret 'Header.'NowHeaders+i '=' Menu.i
  107.         end
  108.     Header.Count = NowHeaders + Menu.Count
  109.  
  110.     REQUESTLIST instem Header SIZEGADGET title '"Headers in current message"'
  111.     if RC = 30 then call ExitMsg(THOR.LASTERROR)
  112.     option = result
  113.     if RC = 5 then return 1
  114.     select
  115.         when option = '' then nop
  116.         when option = 'Add new header' then call AddHeader
  117.         when option = 'Save and exit' then do
  118.             call WriteHeaders
  119.             return 1
  120.             end
  121.         when option = 'HELP' then do
  122.             address command 'MultiView `GetEnv THOR/THORPath`docs/HeaderManager.guide PUBSCREEN' GLOBALCFG.PUBSCREENNAME
  123.             end
  124.         otherwise do
  125.             /* Get number of header selected */
  126.             HdrNo = 0
  127.             do i = 1 to NowHeaders
  128.                 if Header.i = option then HdrNo = i
  129.                 end
  130.  
  131.             REQUESTNOTIFY '"'option'\n\nEdit or Delete this header?"' '"_Edit|_Delete"'
  132.             if RC > 0 then ExitMsg(THOR.LASTERROR)
  133.             if result = 1 then call EditHeader
  134.             else call DeleteHeader
  135.             end
  136.         end
  137.     return 0
  138. ;;;
  139. /* ;;;Read headers in current event */
  140. ReadHeaders:
  141.     address(thorport)
  142.     if ~open(msg,MsgFile,'R') then call ExitMsg('Failed to open message file')
  143.     n = 0
  144.     drop Header.
  145.     Header.Count = n
  146.     do until eof(msg)
  147.         NextLine = readln(msg)
  148.         if length(NextLine)=0 | right(word(NextLine,1),1) ~= ':' then leave
  149.         n = n + 1
  150.         Header.n = NextLine
  151.         Header.Count = n
  152.         end
  153.     call close(msg)
  154.     MsgHeaders = Header.Count
  155.     NowHeaders = Header.Count
  156.     return
  157. ;;;
  158. /* ;;;Update message file with new headers */
  159. WriteHeaders:
  160.     address(thorport)
  161.     OutFile = 'T:ThorHeaders.'time(s)
  162.     if ~open(msg,MsgFile,'R') then call ExitMsg('Failed to open message file')
  163.     if ~open(out,OutFile,'W') then call ExitMsg('Failed to open temporary file')
  164.     do i = 1 to MsgHeaders
  165.         call readln(msg)
  166.         end
  167.     do i = 1 to NowHeaders
  168.         if length(Header.i) <= MaxHeaderLength then call writeln(out,Header.i)
  169.         else do
  170.             HeaderType = word(Header.i,1)' '
  171.             Header.i = ','subword(Header.i,2)
  172.             MaxLen = MaxHeaderLength - length(HeaderType)
  173.             do while Header.i > ''
  174.                 breakpoint = lastpos(',',left(Header.i',', MaxHeaderLength)) - 1
  175.                 parse var Header.i  ',' Header.tmp =breakpoint Header.i
  176.                 writeln(out,HeaderType||Header.tmp)
  177.                 end
  178.             end
  179.         end
  180.     if MsgHeaders = 0 & NowHeaders > 0 then call writeln(out,'')
  181.     do until eof(msg)
  182.         block = readch(msg, 1048576)
  183.         call writech(out,block)
  184.         end
  185.     call close(out)
  186.     call close(msg)
  187.     address command 'copy' OutFile MsgFile
  188.     address command 'delete >NIL:' OutFile
  189.     Changed = 0
  190.     return
  191. ;;;
  192. /* ;;;Add a new header */
  193. AddHeader:
  194.     REQUESTLIST instem HdrMenu SIZEGADGET title '"Choose header to add"'
  195.     if RC = 30 then call ExitMsg(THOR.LASTERROR)
  196.     if RC = 5 then return
  197.     Hdr = result
  198.     select
  199.         when Hdr = 'Cc:' then do
  200.             if IsNews = 0 then call GetAddress
  201.             else do
  202.                 call ShowMsg('Cc: headers not allowed in news')
  203.                 Hdr = ''
  204.                 end
  205.             end
  206.         when Hdr = 'Bcc:' then do
  207.             Hdr = 'bcc:'
  208.             if IsNews = 0 then call GetAddress
  209.             else do
  210.                 call ShowMsg('Bcc: headers not allowed in news')
  211.                 Hdr = ''
  212.                 end
  213.             end
  214.         when Hdr = 'Followup-To:' then do
  215.             if IsNews = 1 then call GetConf
  216.             else do
  217.                 call ShowMsg('Followup-To: headers not allowed in mail')
  218.                 Hdr = ''
  219.                 end
  220.             end
  221.         when Hdr = 'Reply-To:' then do
  222.             call GetAddress
  223.             end
  224.         when Hdr = 'Custom' then do
  225.             REQUESTSTRING title '"Add header"' body '"Enter custom header"' bt '" OK |Cancel"' id '"X-"'
  226.             if RC = 0 then Hdr = result
  227.             else Hdr = ''
  228.             end
  229.         otherwise nop
  230.         end
  231.     if Hdr > '' then do
  232.         NowHeaders = NowHeaders + 1
  233.         Header.Count = NowHeaders
  234.         Header.NowHeaders = Hdr
  235.         Changed = 1
  236.         end
  237.     return
  238. ;;;
  239. /* ;;;Edit a header */
  240. EditHeader:
  241.     HdrType = upper(word(Header.HdrNo,1))
  242.     Hdr = ''
  243.     select
  244.         when HdrType = 'CC:' then do
  245.             Hdr = 'cc:'
  246.             call GetAddress(subword(Header.HdrNo,2))
  247.             end
  248.         when HdrType = 'BCC:' then do
  249.             Hdr = 'bcc:'
  250.             call GetAddress(subword(Header.HdrNo,2))
  251.             end
  252.         when HdrType = 'FOLLOWUP-TO:' then do
  253.             Hdr = 'Followup-To:'
  254.             call GetConf(subword(Header.HdrNo,2))
  255.             end
  256.         when HdrType = 'REPLY-TO:' then do
  257.             Hdr = 'Reply-To:'
  258.             call GetAddress(subword(Header.HdrNo,2))
  259.             end
  260.         otherwise do
  261.             REQUESTSTRING title '"Edit header"' body '"Editing 'Header.HdrNo'"' bt '" OK |Cancel"' id '"'Header.HdrNo'"'
  262.             if RC = 0 then Hdr = result
  263.             end
  264.         end
  265.  
  266.     if Hdr ~= '' then do
  267.         Header.HdrNo = Hdr
  268.         Changed = 1
  269.         end
  270.  
  271.     return
  272. ;;;
  273. /* ;;;Delete a header */
  274. DeleteHeader:
  275.     do i = HdrNo to NowHeaders-1
  276.         interpret 'Header.i = Header.'i+1
  277.         end
  278.     NowHeaders = NowHeaders - 1
  279.     Changed = 1
  280.     return
  281. ;;;
  282. /* ;;;Ask for an email address */
  283. GetAddress:
  284.     parse arg default
  285.     if default > '' then OldHdr = Hdr default                   /* Backup original header */
  286.     else OldHdr = ''
  287.  
  288.     REQUESTSTRING title '"Address header"' body '"Enter email address(es)"' bt '" _OK |_Cancel"' id '"'default'"' maxchars 200
  289.     if RC = 30 then ExitMsg(THOR.LASTERROR)
  290.     if RC = 5 then do                                           /* If nothing entered */
  291.         Hdr = OldHdr
  292.         return
  293.         end
  294.     UserName = result
  295.     UserAddr = ''
  296.     drop USERS. SUG.
  297.     address(bbsread)
  298.     SEARCHBRUSER bbsname '"'System'"' stem USERS search '"'UserName'"' name address alias suggestusersstem SUG
  299.     if RC = 30 then call ExitMsg(BBSREAD.LASTERROR)
  300.     Found = result
  301.     if Found > 0 then do                                        /* Match(es) found */
  302.         drop LIST.
  303.         drop USERTAGS.
  304.         LIST.COUNT = USERS.COUNT
  305.  
  306.         do i = 1 to USERS.COUNT                                 /* Build a list of user names */
  307.             LIST.i.USERNR = USERS.i.USERNR
  308.             READBRUSER bbsname '"'System'"' usernr USERS.i.USERNR tagsstem USERTAGS
  309.             if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
  310.             LIST.i = USERTAGS.NAME
  311.             if(symbol("USERTAGS.ADDRESS") = "VAR") then LIST.i.ADDRESS = USERTAGS.ADDRESS
  312.             end
  313.  
  314.         address(thorport)                                       /* Select a user */
  315.         drop UserName.
  316.         REQUESTLIST instem LIST outstem USERS title '"Select user:"' dragselect
  317.         if RC = 30 then call ExitMsg(THOR.LASTERROR)
  318.  
  319.         do j = 1 to USERS.COUNT
  320.             do i = 1 to LIST.COUNT                              /* Check for email addresses */
  321.                 if LIST.i = USERS.j then UserAddr = UserAddr','LIST.i.ADDRESS
  322.                 end
  323.             end
  324.  
  325.         end
  326.  
  327.     else do                                                     /* No exact match found */
  328.         if(symbol("SUG.COUNT") = "VAR") then do
  329.             address(thorport)
  330.             drop USERS. UserNum.
  331.             REQUESTLIST instem SUG outstem USERS title '"Select user:"' dragselect
  332.             if RC = 30 then call ExitMsg(THOR.LASTERROR)
  333.             if RC = 5 then do                                   /* If cancelled, use address as typed */
  334.                 Hdr = Hdr UserName
  335.                 return
  336.                 end
  337.             do j = 1 to USERS.COUNT
  338.                 do i = 1 to SUG.COUNT                           /* Get the user number */
  339.                     if SUG.i = USERS.j then UserNum.j = SUG.i.USERNR
  340.                     end
  341.                 end
  342.  
  343.             address(bbsread)                                    /* Get data on users selected */
  344.             do i = 1 to USERS.COUNT
  345.                 drop USERTAGS.
  346.                 READBRUSER bbsname '"'System'"' usernr UserNum.i tagsstem USERTAGS
  347.                 if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
  348.                 if(symbol("USERTAGS.ADDRESS") = "VAR") then UserAddr = UserAddr','USERTAGS.ADDRESS
  349.                 end
  350.             end
  351.  
  352.         else do                                                 /* No users found in search */
  353.             call ShowMsg('No matching users found')
  354.             UserAddr = ''
  355.             Hdr = OldHdr
  356.             end
  357.         end
  358.  
  359. if left(UserAddr,1) = ',' then UserAddr = substr(UserAddr,2)
  360. if UserAddr > '' then Hdr = Hdr UserAddr
  361. else Hdr = ''
  362. return
  363. ;;;
  364. /* ;;;Ask for a conference name */
  365. GetConf:
  366.     parse arg default
  367.     if default > '' then OldHdr = Hdr default                      /* Backup original header */
  368.     else OldHdr = ''
  369.  
  370.     address(bbsread)
  371.     drop CONFS. SELECTED.
  372.     GETCONFLIST bbsname '"'System'"' stem CONFS
  373.     if RC = 30 then call ExitMsg(BBSREAD.LASTERROR)
  374.     address(thorport)
  375.     REQUESTLIST instem CONFS outstem SELECTED title '"Select newsgroup(s)"' dragselect
  376.     select
  377.         when RC = 30 then call ExitMsg(THOR.LASTERROR)
  378.         when RC = 5 then Hdr = OldHdr
  379.         otherwise do
  380.             Conf = ''
  381.             do i = 1 to SELECTED.COUNT
  382.                 if upper(SELECTED.i) = 'EMAIL' then SELECTED.i = 'poster'
  383.                 Conf = Conf','SELECTED.i
  384.                 end
  385.             Hdr = Hdr substr(Conf,2)
  386.             end
  387.         end
  388.     return
  389. ;;;
  390.  
  391.